﻿using System;
using OrderMicroService.Domain.Domain.Entity;
using OrderMicroService.Domain.Repository;
using OrderMicroService.Infrastructure.Repository.Common;
using OrderMicroService.Infrastructure.Repository.Converter;
using OrderMicroService.Infrastructure.Repository.DAO;
using OrderMicroService.Infrastructure.Repository.DO;
using OrderMicroService.Types.DTO;
using OrderMicroService.Types.Types;

namespace OrderMicroService.Infrastructure.Repository.Impl
{
    public class OrderRepositoryImpl : DbRepositorySupport<Order, OrderId>, IOrderRepository
    {
        private readonly OrderDAO orderDAO;
        private readonly OrderDoConverter doConverter;

        public OrderRepositoryImpl(OrderDAO orderDAO
            , OrderDoConverter doConverter
            , IAggregateManager<Order, OrderId> aggregateManager) : base(aggregateManager)
        {
            this.orderDAO = orderDAO;
            this.doConverter = doConverter;
        }

        public int Count(OrderQuery query)
        {
            int count = orderDAO.Count(query);
            return count;
        }

        public Page<Order> Query(OrderQuery query)
        {
            var list = orderDAO.Select(query);
            var entitys = doConverter.ToEntitys<OrderDO, Order>(list);
            int count = orderDAO.Count(query);
            return new Page<Order>(entitys, count);
        }

        protected override void OnInsert(Order aggregate)
        {
            throw new NotImplementedException();
        }

        protected override Order OnSelect(OrderId id)
        {
            throw new NotImplementedException();
        }

        protected override void OnUpdate(Order aggregate, EntityDiff diff)
        {
            throw new NotImplementedException();
        }

        protected override void OnDelete(Order aggregate)
        {
            throw new NotImplementedException();
        }
    }
}